<?php
	
	$_userid = $_userid == 1 && $userid  ? $userid : $_userid; // 管理员编辑其他会员信息权限
	
	switch($action){
		case 'add':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			// common
			if(!isset($action)) $action = 'manage';
			require_once 'form.class.php';
			require_once 'includes/certificate.class.php';
			$cert = new certificate();
			$cert->set_userid($userid);
			// common end
			
			if($dosubmit)
			{
				$info['userid'] = $userid;
				$info['name'] = strip_tags($name);
				if(!$info['name']) showmessage('请填写证书名称');
				$info['organization'] = strip_tags($organization);
				if(!$info['organization']) showmessage('请填写发证机构');
				$info['thumb'] = htmlspecialchars($thumb);
				if(!$info['thumb']) showmessage('请上传证书');
				$info['effecttime'] = htmlspecialchars($effecttime);
				$info['endtime'] = htmlspecialchars($endtime);
				$info['addtime'] = TIME;
				$info['status'] = 1;
				$cert->add($info);
				showmessage('证书添加成功！', $forward);
			}
			else
			{
				if($M['ischeck'] && $company_user_infos['status'] == 0) showmessage('您的公司正在审核当中...','goback');
			}
			include template('certificate_add.html','yellowpage');
		break;
		
		case 'manage':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			// common
			if(!isset($action)) $action = 'manage';
			require_once 'form.class.php';
			require_once 'includes/certificate.class.php';
			$cert = new certificate();
			$cert->set_userid($userid);
			// common end
			
			$infos = $cert->listinfo("userid='$userid'",'',$page);
			$pages = $cert->pages;
			include template('certificate_manage.html','yellowpage');
		break;
	
		case 'delete':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			// common
			if(!isset($action)) $action = 'manage';
			require_once 'form.class.php';
			require_once 'includes/certificate.class.php';
			$cert = new certificate();
			$cert->set_userid($userid);
			// common end
			
			$id = intval($id);
			$cert->delete($id);
			showmessage('证书删除成功！', $forward);
			include template('certificate_manage.html','yellowpage');
		break;
		
		case 'edit':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			// common
			if(!isset($action)) $action = 'manage';
			require_once 'form.class.php';
			require_once 'includes/certificate.class.php';
			$cert = new certificate();
			$cert->set_userid($userid);
			// common end
			
			$id = intval($id);
			if($dosubmit)
			{
				$info['name'] = strip_tags($name);
				if(!$info['name']) showmessage('请填写证书名称');
				$info['organization'] = strip_tags($organization);
				if(!$info['organization']) showmessage('请填写发证机构');
				$info['thumb'] = htmlspecialchars($thumb);
				if(!$info['thumb']) showmessage('请上传证书');
				$info['effecttime'] = htmlspecialchars($effecttime);
				$info['endtime'] = htmlspecialchars($endtime);
				if($M['check_cert']) $info['status'] = 0;
				$cert->edit($id,$info);
				showmessage('修改成功！', $forward);
			}
			else
			{
				$info = $cert->get($id);
			}
			
			include template('certificate_edit.html','yellowpage');
		break;
	}
?>